﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace T12OOP
{
    class Program
    {
        static void Main(string[] args)
        {
            #region  类与其构造函数
            Account acc1 = new Account();
            Console.WriteLine(acc1);
            Account acc2 = new Account("张三",1000);
            Console.WriteLine(acc2);
            #endregion


            #region 单例模式
            SingleTon s1 = SingleTon.GetInstance();
            SingleTon s2 = SingleTon.GetInstance();
            if (s1 ==s2)
            {
                Console.WriteLine("SingleTon类的两个实例s1与s2是相同的！");
            }
            #endregion

            #region 属性
            Student stu = new Student();
            stu.Name = "张三";
            //异常处理：友好地对待有可能会出现的错误
            try
            {
                stu.Age = 21;
               // stu.Age = -21;
            }
            catch (Exception)
            {

                Console.WriteLine("年龄不能超过指定范围");
            }
            
            Console.WriteLine(stu);
            #endregion

            #region 索引属性
            Contact c = new Contact();
            //c.Name = "只读属性不能赋值";
            Console.WriteLine(c.Name);
            c["mobile"] = "12345648";
            c["home"] = "12345648";
            c["fax"] = "12345648";
            c["business"] = "12345648";
            Console.WriteLine(c);
            Console.ReadKey();
        }
    }
}
